from django.db import models


# Create your models here.
class Student(models.Model):
    SEX_CHOICES = [
        (0, '女'),
        (1, '男')
    ]
    name = models.CharField(max_length=20, verbose_name='学生姓名', help_text='学生姓名')
    age = models.SmallIntegerField('学生年龄', null=True, blank=True, help_text='学生年龄')  # blank=True 表示前端可以不输入值
    sex = models.SmallIntegerField('学生性别', choices=SEX_CHOICES, help_text='学生性别')
    c_time = models.DateTimeField('创建时间', auto_now_add=True)
    u_time = models.DateTimeField('修改时间', auto_now=True)
    is_delete = models.BooleanField('逻辑删除', default=False, help_text='逻辑删除')  # default=False表示默认情况下不删除 用户以为的删除

    # 关联字段
    classes = models.ForeignKey('classes', on_delete=models.SET_NULL, null=True, verbose_name='班级', help_text='班级')

    # 重写delete方法，实现逻辑删除
    def delete(self, using=None, keep_parents=False):
        self.is_delete = True
        self.save()


class Classes(models.Model):
    name = models.CharField(max_length=20, verbose_name='班级名称', help_text='班级名称')
    num = models.CharField('班期', max_length=20, help_text='班期')
    c_time = models.DateTimeField('创建时间', auto_now_add=True)
    u_time = models.DateTimeField('修改时间', auto_now=True)
    is_delete = models.BooleanField('逻辑删除', default=False, help_text='逻辑删除')

    # 重写delete方法，实现逻辑删除
    def delete(self, using=None, keep_parents=False):
        self.is_delete = True
        self.save()

# 将具体的值传入表单
    def __str__(self):
        return f'{self.name}-{self.num}期'
